package com.comall.dc.banktest.storage;

import com.comall.dc.banktest.domain.model.AccountRecord;
import com.comall.dc.banktest.domain.repository.AccountRecordRepository;
import com.comall.dc.banktest.infrastructure.dao.service.AccountRecordDAO;
import com.comall.dc.banktest.infrastructure.entity.AccountRecordPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class AccountRecordStorage implements AccountRecordRepository {

    @Autowired
    private AccountRecordDAO accountRecordService;

    @Override
    public AccountRecord save(AccountRecord accountRecord) {
        AccountRecordPO accountRecordPO = new AccountRecordPO();
        accountRecordPO.setFromAccountId(accountRecord.getFromAccountId());
        accountRecordPO.setToAccountId(accountRecord.getToAccountId());
        accountRecordPO.setCreateTime(accountRecord.getCreateTime());
        accountRecordPO.setValue(accountRecord.getValue());
        accountRecordPO.setOperation(accountRecord.getOperation().getOperation());
        accountRecordService.save(accountRecordPO);
        return new AccountRecord(accountRecordPO);
    }

}
